#include "hex.h"

//void main(){
//    char *str = "0123456789abcdef0123456789abcdef";
//    char *buf = hex(str);
//    printf("%d:%s\r\n", strlen(buf), buf);
//}

char *hex(char *str)
{
    int len = strlen(str);
    unsigned char *hex = malloc(len * 2);
    unsigned char *buf = malloc(2);
    int i;
    for (i = 0; i < len; ++i) {
        sprintf(buf, "%02X", *(str + i) & 0xff);
        strncat(hex, buf, 2);
    }
    return hex;
}